#!/usr/bin/node

const log = console.log;

function Radio(station) {
  const _listeners = {};

  setTimeout(()=>{
    emit('open',station);
  },0);

  setTimeout(()=>{
    emit('stop',station);
  },5000);

  function emit(evt,arg){
    if(typeof(_listeners[evt])==='undefined'){
      log('error!');
      process.exit(1);
    }
    _listeners[evt].forEach(fn=>{
      fn.call(this,arg);
    });
  }
  this.on = (evt,fn)=>{
    if(typeof _listeners[evt] === 'undefined'){
      _listeners[evt] = [];
    }

    _listeners[evt].push(fn);
  };

}

module.exports = Radio;
